Skip to content

feat(csp): receive browser CSP and Reporting API reports, show them in the web UI and over MCP - #382

Closed
roxblnfk wants to merge 2 commits into
masterfrom
feat/csp-reports
Closed

roxblnfk wants to merge 2 commits into
masterfrom
feat/csp-reports

Conversation

@roxblnfk

Copy link
Copy Markdown
Member

🔍 What was changed

  • Trap receives browser security reports as buggregator/server 2.14 does: a POST with application/csp-report or application/reports+json on any path, or any POST to /csp and /csp/{project}. Both formats become one report shape; a report-to batch of several reports (csp-violation, deprecation, intervention, crash…) is one csp event.
  • The web UI shows its CSP reports page, the console prints a block per report, and the MCP event tools read them: type: csp, fields report_type, directive, blocked, disposition, page, source_file, and a get_event text with the page, directive, blocked resource, disposition, source line and sample. No dedicated tool: the event tools read well enough.
  • trap test sends a report of each format. New docs/csp.md with recipes for plain PHP, Reporting-Endpoints, Laravel and Symfony; the trap skill gets a csp.md reference with a fix-the-policy recipe for agents.

How it works

  • The project is the {project} of the path, else the password of the Basic user csp, else X-Buggregator-Project. A request with X-Buggregator-Event or a Basic user of another type is left to its module.
  • Answers: 204 with an empty body, 400 for a body that is no report, 413 above 1 MiB. The CSP module sits after the other sources and before the HTTP dump, so it takes nothing of theirs.

Review notes

  • Chrome delivers Reporting API reports to another origin only after a CORS preflight; without an answer it drops them silently (seen in headless Chromium: OPTIONS dumped, no reports). So OPTIONS /csp[/…] gets a preflight answer for any origin. It checks nothing, but it is a CORS answer: say if you would rather leave report-to to same-origin endpoints.
  • In Chromium, Reporting-Endpoints works only from an HTTPS page to an https:// endpoint; to http://127.0.0.1 nothing is sent. report-uri works from HTTP and HTTPS pages to http://127.0.0.1. The docs say so.
  • The UI's setup hint fills {http_port} with the port of the page, so with the UI on a port of its own it points at the UI port, which takes no reports. That is the same for every hint of the UI and is already in docs/web-ui.md.

Checklist

  • How was this tested:
    • Unit tests added; Unit, Arch and Acceptance suites run locally (the known ProtobufCasterTest failures aside)
    • Tested manually: curl with both formats, and headless Chromium with Report-Only pages using report-uri and report-to against a running Trap; the CSP reports page, its detail pages and the setup hint checked in the UI; list_events and get_event over MCP
    • Firefox and Safari not tried

Documentation

  • docs/csp.md (new), docs/mcp.md, docs/web-ui.md, docs/cli.md, docs/http-dump.md, docs/agent-skills.md, README; skill: SKILL.md, references/csp.md (new), references/mcp.md.

…n the web UI and over MCP

As buggregator/server 2.14 does, Trap takes a POST with `application/csp-report` or `application/reports+json` on any path, or any POST to `/csp` and `/csp/{project}`, reads both formats into one report shape and answers 204. The CSP reports page of the web UI shows them, the console prints a block per report, and the MCP event tools list, filter (`report_type`, `directive`, `blocked`, `disposition`, `page`, `source_file`) and read them. A request marked for another module is left to it; a body over 1 MiB gets 413, one that is no report 400. `trap test` sends a report of each format.

Chrome delivers Reporting API reports to another origin only after a CORS preflight, so an OPTIONS to `/csp` paths is answered for any origin; it is not an origin check. docs/csp.md and the skill's csp reference set up a Report-Only policy for plain PHP, Laravel and Symfony.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added enhancement New feature or request tests Changes in the tests labels Nov 23, 2026
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.79845% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.78%. Comparing base (73bea3d) to head (2a9060d).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/Server/Command/Test.php 0.00% 10 Missing ⚠️
src/Module/Csp/Module.php 50.00% 3 Missing ⚠️
src/Module/Csp/Mcp/CspView.php 93.54% 2 Missing ⚠️
src/Module/Csp/Report.php 98.79% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #382      +/-   ##
==========================================
+ Coverage   80.55%   80.78%   +0.23%     
==========================================
  Files         432      441       +9     
  Lines       17488    17813     +325     
==========================================
+ Hits        14087    14390     +303     
- Misses       3401     3423      +22     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…t type

fix(csp): escape the project in the console header
feat(csp): show the failure of `network-error` and the reason of `crash` reports
docs(csp): name the project of browser reports in the path; Network Error Logging

As buggregator/server does, `X-Buggregator-Event: csp` or the Basic user `csp` marks a report whatever its path and type; the header goes before the Basic user. A project with markup, such as `/csp/%3Cerror%3Ered`, made the console print nothing. A browser sends no userinfo credentials and adds no headers to a report, so the docs and the skill name the project in `/csp/{project}` and leave Basic and `X-Buggregator-Project` to proxies and other clients.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@roxblnfk

Copy link
Copy Markdown
Member Author

Landed on master as a fast-forward of one signed commit: 9ff91cf (c1d34f3 + 2a9060d + a docblock wrap, on top of the Ray pause commits).

@roxblnfk roxblnfk closed this Nov 23, 2026
@roxblnfk
roxblnfk deleted the feat/csp-reports branch November 24, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tests Changes in the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant